var util = require('../../../utils/util.js');
var api = require('../../../config/api.js');
var wxcache = require('../../../utils/wxcache.js');


var app = getApp();

Page({
  data: {
    showBottom: false,
    refundList: [],
    loadMoreData: '~人家也是有底线的喔~',
    loadingHidden:false
  },
  pageSize: 5,
  currentPageNum: 0,

  onLoad: function (options) {

  },
  onReady: function () {

  },
  onShow: function () {
    this.getRefundList();

  },
  onHide: function () {
    // 页面隐藏

  },
  onUnload: function () {
    // 页面关闭
  },
  getRefundList() {
    let that = this;

    util.request(api.RefundList,{},"POST").then(function (res) {
      console.log(res); 
      
      if (res.code == 200) {
         that.setData({
           refundList: res.responseBody.refundOrderRespList,
           loadingHidden:true
 
         })
      }
    });
  },
  touchItem: function (e) {
    console.log(e)
    // var campaign_id = e.currentTarget.dataset.citem.campaignId;
    // wx.navigateTo({
    //   url: '/pages/goods/goods?id=' + campaign_id,
    // })
    var orderId = e.currentTarget.dataset.citem.orderId;
    wx.navigateTo({
      url: '/pages/ucenter/aftersales/refunddetails/refunddetails?orderId=' + orderId,
    })
  },
  toRefundDetail: function (e) {
    console.log(e)
    var orderId = e.currentTarget.dataset.citem.orderId;
    wx.navigateTo({
      url: '/pages/ucenter/aftersales/refunddetails/refunddetails?orderId=' + orderId,
    })
  },
  /**
   * 监听页面上拉触底事件
   */
  onReachBottom: function () {
    var that = this;
    var nowPageSize = that.pageSize + 5
    var currentPage = that.currentPageNum

    if (!that.data.showBottom) {
      wx.showLoading({
        title: '玩命加载中',
        mask:true
      })
      console.log('参数',currentPage,nowPageSize)
      util.request(api.RefundList, {
        pageSize: nowPageSize
      }, 'POST').then(function (res) {

        console.log(res)

        if (res.code == 200) {

          var refundList = res.responseBody.refundOrderRespList
          //列表加载完毕，显示
          if (refundList.length == that.currentPageNum || refundList.length < 5) {
            that.setData({
              showBottom: true
            })
          }

          that.setData({
            refundList: refundList
          })
        }
      
        that.pageSize = that.pageSize + 5,
          that.currentPageNum = refundList.length

        wx.hideLoading()

      }, function (error) {
        console.log('获取失败')
      })
    }


  }

})